home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / datatypes / debox_dt / source / classbase.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  4KB  |  144 lines

  1.  
  2. /******************************************************************************
  3.  *
  4.  * Flowerpower's DeBox Datatype
  5.  *
  6.  * Written by Christian Buchner and David N. Junod
  7.  *
  8.  ******************************************************************************
  9.  * classbase.c
  10.  *
  11.  */
  12.  
  13. #include "classbase.h"
  14.  
  15. /*****************************************************************************/
  16.  
  17. #define    DB(x)    ;
  18.  
  19. /*****************************************************************************/
  20.  
  21. Class *__asm ObtainClassEngine (register __a6 struct ClassBase *cb)
  22. {
  23.     return (cb->cb_Class);
  24. }
  25.  
  26. /*****************************************************************************/
  27.  
  28. struct Library *__asm LibInit (register __d0 struct ClassBase *cb, register __a0 BPTR seglist, register __a6 struct Library * sysbase)
  29. {
  30.     cb->cb_SegList = seglist;
  31.     cb->cb_SysBase = sysbase;
  32.     InitSemaphore (&cb->cb_Lock);
  33.     if (cb->cb_SysBase->lib_Version >= 39)
  34.     {
  35.         cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  36.         cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  37.         cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  38.         cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  39.         return cb;
  40.     }
  41.     else
  42.     {
  43.         return NULL;
  44.     }
  45. }
  46.  
  47. /*****************************************************************************/
  48.  
  49. LONG __asm LibOpen (register __a6 struct ClassBase *cb)
  50. {
  51.     LONG retval = (LONG) cb;
  52.     BOOL success = TRUE;
  53.     
  54.     ObtainSemaphore (&cb->cb_Lock);
  55.     
  56.     /* Use an internal use counter */
  57.     cb->cb_Lib.lib_OpenCnt++;
  58.     cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  59.     
  60.     if (cb->cb_Lib.lib_OpenCnt == 1)
  61.     {
  62.         if (cb->cb_Class == NULL)
  63.         {
  64.             success = FALSE;
  65.             if (cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39))
  66.                 if (cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39))
  67.                     if (cb->cb_SuperClassBase = OpenLibrary ("datatypes/picture.datatype", 39))
  68.                         if (cb->cb_Class = initClass (cb))
  69.                             success = TRUE;
  70.         }
  71.     }
  72.     
  73.     if (!success)
  74.     {
  75.         CloseLibrary (cb->cb_SuperClassBase);
  76.         CloseLibrary (cb->cb_DataTypesBase);
  77.         CloseLibrary (cb->cb_IFFParseBase);
  78.         cb->cb_IFFParseBase = cb->cb_DataTypesBase = cb->cb_SuperClassBase = NULL;
  79.         
  80.         cb->cb_Lib.lib_OpenCnt--;
  81.         retval = NULL;
  82.     }
  83.     
  84.     ReleaseSemaphore (&cb->cb_Lock);
  85.     
  86.     return (retval);
  87. }
  88.  
  89. /*****************************************************************************/
  90.  
  91. LONG __asm LibClose (register __a6 struct ClassBase *cb)
  92. {
  93.     LONG retval = NULL;
  94.     
  95.     ObtainSemaphore (&cb->cb_Lock);
  96.     
  97.     if (cb->cb_Lib.lib_OpenCnt)
  98.     cb->cb_Lib.lib_OpenCnt--;
  99.     
  100.     if ((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  101.     {
  102.         if (FreeClass (cb->cb_Class))
  103.         {
  104.             cb->cb_Class = NULL;
  105.             CloseLibrary (cb->cb_SuperClassBase);
  106.             CloseLibrary (cb->cb_DataTypesBase);
  107.             CloseLibrary (cb->cb_IFFParseBase);
  108.         }
  109.         else
  110.         cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  111.     }
  112.     
  113.     if (cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  114.     retval = LibExpunge (cb);
  115.     
  116.     ReleaseSemaphore (&cb->cb_Lock);
  117.     
  118.     return (retval);
  119. }
  120.  
  121. /*****************************************************************************/
  122.  
  123. LONG __asm LibExpunge (register __a6 struct ClassBase *cb)
  124. {
  125.     BPTR seg = cb->cb_SegList;
  126.     
  127.     Remove ((struct Node *) cb);
  128.     
  129.     CloseLibrary (cb->cb_UtilityBase);
  130.     CloseLibrary (cb->cb_DOSBase);
  131.     CloseLibrary (cb->cb_GfxBase);
  132.     CloseLibrary (cb->cb_IntuitionBase);
  133.     
  134.     FreeMem ((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  135.     
  136.     return ((LONG) seg);
  137. }
  138.  
  139. /*****************************************************************************/
  140.  
  141. void __asm LibReserved(register __a6 struct ClassBase *cb)
  142. {
  143. }
  144.